package com.jsh.erp.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashSet;


/**
* @Author: wy
* @Description: mybatis plus 默认值配置
* @DateTime: 2022-09-09 11:39
* @Params:
* @Return
*/
@Component
public class MetaObjectHandlerConfig implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        String[] setterNames = metaObject.getSetterNames();
        HashSet<String> setterNameSet = new HashSet<>(Arrays.asList(setterNames));
        if (setterNameSet.contains("uploadFlag")) {
            //默认未删除
            setFieldValByName("uploadFlag", "1", metaObject);
        }

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        String[] setterNames = metaObject.getSetterNames();
        HashSet<String> setterNameSet = new HashSet<>(Arrays.asList(setterNames));
        if (setterNameSet.contains("uploadFlag")) {
            //默认未删除
            setFieldValByName("uploadFlag","1", metaObject);
        }
    }
}
